package com.itsm.controller;

import com.alibaba.fastjson.JSONObject;
import com.itsm.config.WeComProperties;
import com.itsm.entity.File;
import com.itsm.entity.User;
import com.itsm.service.AccessTokenService;
import com.itsm.service.LoginService;
import com.itsm.service.UrlRequestService;
import com.itsm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@RestController
public class UserController {

//    @Resource
//    private WeComProperties properties;
    @Autowired
    private UrlRequestService urlRequestService;

    @Autowired
    private AccessTokenService accessTokenService;

    @Autowired
    private UserService userService;

    @Autowired
    private LoginService loginService;

    /**
     * 获取是工程师的人员姓名，id
     * @return
     * @throws
     */
    @GetMapping("getEnName")
    public Object getEnName(HttpServletRequest request)  {
        String name = (String) request.getSession().getAttribute("name");
//        String staffNum = (String) request.getSession().getAttribute("alias");
        if(userService.selectEn(name)==null){
            return null;
        }
        return userService.selectEn(name);
    }


    /**
     * 获取是工程师的人员姓名，id
     * @return
     * @throws
     */
    @GetMapping("getRespaName")
    public Object getRespaName()  {
        return userService.selectName("工程师");
    }

    /**
     * 获取全部用户
      * @return
     */
    @GetMapping("getAllUser")
    public List<User> getAllUser(){
        return userService.getAllUser();
    }

    @GetMapping("getAllName")
    public List<File> getAllName(HttpServletRequest request){
        String userid = (String) request.getSession().getAttribute("userid");
        return userService.getAllName(userid);
    }
    @GetMapping("getUser")
    public User getPost(HttpServletRequest request){
        String userid = (String) request.getSession().getAttribute("userid");
        return userService.selectUser(userid);
    }


    @GetMapping("getMy")
    public String getMy(HttpServletRequest request){

        return (String) request.getSession().getAttribute("name");
    }




}
